package com.restaurant.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.restaurant.entity.Company;
import com.restaurant.entity.Transport;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;


@Mapper
public interface CompanyMapper extends BaseMapper<Company> {

    @Update(" UPDATE company c\n" +
            "    INNER JOIN user u ON c.id = u.company_id\n" +
            "    INNER JOIN product_record pr ON pr.user_id = u.id\n" +
            "    SET c.count = c.count + 1\n" +
            "    WHERE pr.user_id = #{userId}")
    void updateCompanyCount(Long userId);

    @Update(" UPDATE company c\n" +
            "    INNER JOIN user u ON c.id = u.company_id\n" +
            "    INNER JOIN transport_record pr ON pr.user_id = u.id\n" +
            "    SET c.count = c.count + 1\n" +
            "    WHERE pr.user_id = #{userId}")
    void updateCompanyCount2(Long userId);

//    @Update("UPDATE company c " +
//            "INNER JOIN user u ON c.id = u.company_id " +
//            "SET c.count = c.count + 1 " +
//            "WHERE EXISTS (SELECT 1 FROM product_record pr WHERE pr.user_id = u.id AND pr.user_id = #{userId})")
//    void updateCompanyCount(Long userId);
//
//    @Update("UPDATE company c " +
//            "INNER JOIN user u ON c.id = u.company_id " +
//            "SET c.count = c.count + 1 " +
//            "WHERE EXISTS (SELECT 1 FROM transport_record tr WHERE tr.user_id = u.id AND tr.user_id = #{userId})")
//    void updateCompanyCount2(Long userId);
    @Update("UPDATE company\n" +
            "    SET count = 0")
    void updatea();
}
